from collections import abc
from functools import singledispatch
import html
import numbers

@singledispatch
def htmlize(obj):
    content = html.escape(repr(obj))
    return '<pre>{}</pre>'.format(content)

@htmlize.register(str)
def _(text):
    content = html.escape(text).replace('\n', '<br>\n')
    return '<p>{}</p>'.format(content)

@htmlize.register(numbers.Integral)
def _(n):
    return '<a>{}</a>'.format(n)

@htmlize.register(tuple)
@htmlize.register(abc.MutableSequence)
def _(seq):
    inner = '</li>\n</li>'.join(htmlize(item) for item in seq)
    return inner

if __name__ == '__main__':
    x = htmlize('abc')
    x = htmlize(3)
    x = htmlize([1,2,'aa'])
    print(x)